//          https://ac.nowcoder.com/acm/contest/5026/C





#include <iostream>
#include <vector>

using namespace std;

int p[4];
int fa[20];
int t[20];
int ans = 0;

int findParent(int x)
{
    if (fa[x] != x)
        fa[x] = findParent(fa[x]);

    return fa[x];
}

void dfs(int x)
{
    if (x == 13)
    {
        ans++;
        return;
    }
    if (t[x] == 0)
        dfs(x + 1);
    else
    {
        for (int i = 0; i < 4; i++)
            if (t[x] <= p[i])
            {
                p[i] -= t[x];
                dfs(x + 1);
                p[i] += t[x];
            }
    }
}

int main()
{
    for (int i = 1; i <= 12; i++)
        fa[i] = i;

    int m, x, y;
    cin >> p[0] >> p[1] >> p[2] >> p[3] >> m;
    for (int i = 1; i <= m; i++)
    {
        cin >> x >> y;
        int fx = findParent(x), fy = findParent(y);
        if (fx != fy)
            fa[fx] = fy;
    }
    for (int i = 1; i <= 12; i++)
        t[findParent(i)]++;

    dfs(1);
    cout << ans << endl;
    return 0;
}